﻿Imports System
Imports System.Net
Imports System.IO
Imports System.Threading

Public Class LoginForm1

    

    ' TODO: 插入代码，以使用提供的用户名和密码执行自定义的身份验证
    ' (请参见 http://go.microsoft.com/fwlink/?LinkId=35339)。 
    ' 随后自定义主体可附加到当前线程的主体，如下所示: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' 其中 CustomPrincipal 是用于执行身份验证的 IPrincipal 实现。 
    ' 随后，My.User 将返回 CustomPrincipal 对象中封装的标识信息
    ' 如用户名、显示名等
    Dim ftp As FtpMod = New FtpMod()

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Me.TextBox1.Text = "adm"
        Me.TextBox2.Text = "123456"

        Try
            If FtpMod.Download(Me.TextBox1.Text, Me.TextBox2.Text, "ftp://192.168.1.233/Class1/shipin/", "test.wmv") = True Then
                Me.Visible = False
                Form1.Visible = True
                Form1.Text = "CG英雄动漫教育（管理员）"
            ElseIf FtpMod.Upload(Me.TextBox1.Text, Me.TextBox2.Text, "ftp://192.168.1.233/shipin/", "c:\123\test.txt") = True Then
                Me.Visible = False
                Form1.Visible = True
                Form1.Text = "CG英雄动漫教育（教师）"
            ElseIf FtpMod.Download(Me.TextBox1.Text, Me.TextBox2.Text, "ftp://192.168.1.233/sucai/", "test.txt") = True Then
                Me.Visible = False
                Form1.Visible = True
                Form1.Text = "CG英雄动漫教育（学生）"
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        ''==========================测试用===========================================
        'Me.Visible = False
        'Form1.Visible = True
        ''=============================================================================
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub UsernameLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsernameLabel.Click

    End Sub

    Private Sub PasswordTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub UsernameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub PasswordLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasswordLabel.Click

    End Sub

    'Public Sub Upload(filename As String)
    '    Dim fileInf As FileInfo = New FileInfo("c:\mywork\" + filename)
    '    Dim uri As String
    '    uri = "ftp://192.168.1.233/" + fileInf.Name
    '    Dim reqFtp As FtpWebRequest

    '    reqFtp = FtpWebRequest.Create(New Uri(uri))
    '    reqFtp.Credentials = New NetworkCredential("James", "123456")
    '    reqFtp.KeepAlive = False
    '    reqFtp.UsePassive = False
    '    reqFtp.Method = WebRequestMethods.Ftp.UploadFile
    '    reqFtp.UseBinary = True
    '    reqFtp.ContentLength = fileInf.Length
    '    Dim b(1024) As Byte
    '    Dim contenlen As Integer
    '    Dim fs As FileStream = fileInf.OpenRead()
    '    Dim strm As Stream = reqFtp.GetRequestStream()
    '    contenlen = fs.Read(b, 0, 1024)
    '    While contenlen <> 0
    '        strm.Write(b, 0, contenlen)
    '        contenlen = fs.Read(b, 0, 1024)

    '    End While
    '    strm.Close()
    '    fs.Close()


    'End Sub



End Class
